using TestCases.CompareAssert.Core.Comparers.Interfaces;
using TestCases.CompareAssert.Core.Interfaces;

namespace TestCases.CompareAssert.Core.Comparers.Stateless
{
    public class HashCodeComparer: IObjectComparer
    {
        public const string IdentifiableName = "HashCodeComparer";

        private static readonly HashCodeComparer _instance = new HashCodeComparer();

// Explicit static constructor to tell C# compiler not to mark type as beforefieldinit
// ReSharper disable EmptyConstructor
        static HashCodeComparer()
// ReSharper restore EmptyConstructor
        {
        }

        private HashCodeComparer()
        {
        }

        public static HashCodeComparer Instance
        {
            get { return _instance; }
        }        
        
        
        public string Name
        {
            get { return IdentifiableName; }
        }

        public IResultBuilder Compare(ICompareContext context)
        {
            int leftHashCode = context.LValue.GetHashCode(), rightHashCode = context.RValue.GetHashCode();
            var hashCodeContext = context.ForMethodObjects(leftHashCode, rightHashCode, "GetHashCode");
            return this.IsBoolResult(leftHashCode == rightHashCode, hashCodeContext);
        }
    }
}